package com.online.teaching.module.student.homework.controller;

import com.online.teaching.module.student.homework.domian.dto.AnswerAddDTO;
import com.online.teaching.module.student.homework.domian.dto.AnswerUpdateDTO;
import com.online.teaching.module.student.homework.service.StudentHomeworkService;
import com.online.teaching.module.student.takes.domain.vo.GetHomeWorkListVO;
import com.online.teaching.utils.StatusCode;
import com.online.teaching.utils.TokenDecode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.online.teaching.utils.Result;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName : StudentBlogController  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:20  //时间
 */
@Api(tags ="学生作业模块")
@RestController
public class StudentHomeworkController {

    @Autowired
    private StudentHomeworkService studentHomeworkService;

    @Autowired
    private TokenDecode tokenDecode;

    @ApiOperation(value = "学生查询作业列表", notes = "学生查询作业列表")
    @GetMapping("student/homework/getHomeworkList")
    public Result<List<GetHomeWorkListVO>> getHomeworkList(@ApiParam("teachesId") @RequestParam("teachesId")Integer teachesId)
    {
        Integer id = Integer.valueOf(tokenDecode.getUserInfo().get("id"));
        List<GetHomeWorkListVO> homeworkList = studentHomeworkService.getHomeworkList(teachesId, id);
        return new Result(true, StatusCode.OK,"查询成功",homeworkList);
    }

    @ApiOperation(value = "学生上传作业", notes = "学生上传作业")
    @PostMapping("student/homework/addAnswer")
    public Result addAnswer(@RequestBody @Valid AnswerAddDTO answerAddDTO)
    {
        int i = studentHomeworkService.addAnswer(answerAddDTO);
        return i==1?new Result(true, StatusCode.OK,"提交成功"):new Result(true, StatusCode.ERROR,"提交失败");
    }

}
